#include "Light.h"

namespace Horse
{
	ILight::ILight(const QColor& color)
		: m_color(color)
	{
	}
	AmbientLight::AmbientLight(const QColor& color, float strength)
		: ILight(color)
		, m_strength(strength)
	{
	}
	void AmbientLight::useLight(QOpenGLShaderProgram* shaderProgram)
	{
		shaderProgram->setUniformValue("u_ambientLight.color", m_color);
		shaderProgram->setUniformValue("u_ambientLight.strength", m_strength);
	}
	AmbientLight::~AmbientLight()
	{
	}
	LightManager::LightManager()
		:m_ambientLight(new AmbientLight(Qt::white, 0.3f))
	{
	}
	QString& LightManager::createLightShader(QString& code)
	{
		int idx = code.indexOf("/*[[USE_LIGHT]]*/");
		if (idx > 0)
		{
			code = code.replace("/*[[USE_LIGHT]]*/", "#define USE_AMBIENTLIGHT");
		}
		return code;
	}
	LightManager* LightManager::getLightManager()
	{
		static LightManager* manager = new LightManager();
		return manager;
	}
	void LightManager::useLights(QOpenGLShaderProgram* shaderProgram)
	{
		m_ambientLight->useLight(shaderProgram);
	}
}
